From 3c9536652a3b27ec97cb2e3f046c5e98849c58a4 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 11 May 2008 19:49:08 +0000 Subject: [PATCH] Put code to view redirect page in new method Article::viewRedirect in order to allow displaying redirects on foreign file repos. --- includes/Article.php | 33 ++++++++++++++++++++++----------- includes/ImagePage.php | 13 +++++++++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 1558efdcbc..cef4470b9e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -860,18 +860,8 @@ class Article { } elseif ( $rt = Title::newFromRedirect( $text ) ) { - # Display redirect - $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; - $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; # Don't overwrite the subtitle if this was an old revision - if( !$wasRedirected && $this->isCurrent() ) { - $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) ); - } - $link = $sk->makeLinkObj( $rt, htmlspecialchars( $rt->getFullText() ) ); - - $wgOut->addHTML( '#REDIRECT ' . - ''.$link.'' ); - + $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ); $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser)); $wgOut->addParserOutputNoText( $parseout ); } else if ( $pcache ) { @@ -933,6 +923,27 @@ class Article { $this->viewUpdates(); wfProfileOut( __METHOD__ ); } + + protected function viewRedirect( $target, $overwriteSubtitle = true, $forceKnown = false ) { + global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser; + + # Display redirect + $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; + $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; + + if( $overwriteSubtitle ) { + $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) ); + } + $sk = $wgUser->getSkin(); + if ( $forceKnown ) + $link = $sk->makeKnownLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); + else + $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); + + $wgOut->addHTML( '#REDIRECT ' . + ''.$link.'' ); + + } function addTrackbacks() { global $wgOut, $wgUser; diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 7579399772..4dacae30d8 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -44,8 +44,17 @@ class ImagePage extends Article { function view() { global $wgOut, $wgShowEXIF, $wgRequest, $wgUser; - if ( $this->img->getRedirected() ) - return Article::view(); + if ( $this->img->getRedirected() ) { + if ( $this->mTitle->getDBkey() == $this->img->getName() ) { + return Article::view(); + } else { + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ), + /* $overwriteSubtitle */ true, /* $forceKnown */ true ); + $this->viewUpdates(); + return; + } + } $diff = $wgRequest->getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); -- 2.20.1